//
//  CZTabBarViewController.swift
//  git
//
//  Created by 徐 鹏超 on 16/4/8.
//  Copyright © 2016年 徐 鹏飞. All rights reserved.
//

import UIKit

class CZTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewController(CZHomeViewController(), image: "tabbar_home", title: "首页")
        addChildViewController(CZMessageViewController(), image: "tabbar_message_center", title: "消息")
        addChildViewController(CZFindViewController(), image: "tabbar_discover", title: "发现")
        
        addChildViewController(CZSettingViewController(), image: "tabbar_profile", title: "设置")
        
        let czTabBar = CZTabBar()
        
        setValue(czTabBar, forKey: "tabBar")
        
        czTabBar.composeButton.addTarget(self, action: "showPublish", forControlEvents: UIControlEvents.TouchUpInside)
    }

    
    func showPublish(){
        
        print("你点击我了")
        //model一个控制器
        let publish = CZPublishViewController()
        // 2
        let nav = UINavigationController(rootViewController: publish)
        // 3
        presentViewController(nav, animated: true) { () -> Void in
            
        }
    }
    
    ///重载
    /*
    参数类型/个数不同
    */
    func addChildViewController(childController: UIViewController,image: String,title: String) {
        //
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        childController.tabBarItem.image = UIImage(named: image)
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
        childController.title = title
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
    }
    
    
    
    
   
    
    
    
    
    
    
}
